//导入的debounce(防抖)函数
import { debounce } from './utils.js'
//返回顶部按钮的组件引入
import backTop from '../components/content/backTop/backTop.vue'
import { POP, NEW, SELL } from "./const";



// 混入的操作，把不同组件的公共的代码抽取到混入里面
export const itemListenerMixin = {
    // 把需要的属性都可以放到混入里面
    data() {
        return {
            itemImageListener: null,
            refresh: null,
        }
    },
    mounted() {
        // 监听图片的加载情况，如果不用的debounce函数，就加载一张图片就请求数据，这样服务器任务重
        // 所以就有这个函数，会等图片加载完了在执行
        this.refresh = debounce(this.$refs.scroller.refresh, 50)
        this.itemImageListener = () => {
            this.refresh()
        }
        this.$bus.$on('itemImageLoad', this.itemImageListener);
        console.log('我是混入的内容')

    }
}

export const backTopMixin = {
    components: {
        backTop
    },
    data() {
        return {
            isShoeBackTop: false
        }
    },
    methods: {
        //点击按钮返回顶部
        backClick() {
            this.$refs.scroller.scrollTo(0, 0, 1000)
        },
        isShowBackTop(position) {
            this.isShoeBackTop = (-position.y) > 1000
        }
    },
}
export const tabControlMixin = {
    data: function() {
        return {
            currentType: POP
        }
    },
    methods: {
        tabClick(index) {
            switch (index) {
                case 0:
                    this.currentType = POP
                    break
                case 1:
                    this.currentType = NEW
                    break
                case 2:
                    this.currentType = SELL
                    break
            }
            console.log(this.currentType);
        }
    }
}